#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

const int MAXLETTERS = 10000;
const int MAXCUBES = 10000;

bool bfs(const vector<vector <int> >& graph, const vector<vector <int> >& flow, int start, int finish, vector<int>& parents) {
    const int n = graph.size();
    parents.resize(n, -1);
    queue<int> q;
    q.push(start);
    vector<bool> used(n);
    used[start] = true;

    while(!q.empty()) {
        int v = q.front();
        q.pop();
        for (int i = 0; i < graph[v].size(); i++) {
            int to = graph[v][i];
            if (v < to && flow[v][i] < 1 || v > to && flow[to][i] < 0) {
                q.push(to);
                parents[to] = v;
                used[to] = true;
            }

        }

        if (used[finish]) {
            break;
        }

    }

    if (!used[finish])
        return false;
    else return true;

}

int main() {

    char letters[MAXLETTERS];
    int l_size = 0;
    char cubes[MAXCUBES][6];
    int c_size = 0;

    scanf("%s", letters);

    while(letters[l_size++]);
    l_size--;

    cin >> c_size;

    char c;
    for (int i = 0; i < c_size; i++) {
        scanf("%s", cubes[i]);
    }

    vector< vector<int> > graph(l_size + c_size + 2); //списки смежности
    vector<vector<int> > flow(l_size + c_size + 2); //текущий поток по ребрам

    //0 - исток, 1..l_size - буквы, l_size+1..l_size+c_size - кубики, l_size+c_size+1 - сток

    //установим соответствие между буквами алфавита и кубиками
    vector< vector<int> > compliance(26);
    for (int i = 0; i < 26; i++)
        for (int j = 0; j < c_size; j++)
            for (int k = 0; k < 6; k++)
                if ('A'+i == cubes[j][k]) {
                    compliance[i].push_back(l_size + 1 + j);
                    break;
                }

    //и построим граф на основе этого
    for (int i = 0; i < l_size; i++) {
        graph[i+1] = compliance[letters[i] - 'A'];
        flow[i+1].resize(graph[i+1].size(), 0);
        for (int j = 0; j < graph[i+1].size(); j++) {
            graph[graph[i+1][j]].push_back(i+1);
            flow[graph[i+1][j]].push_back(0);
        }
    }

    //из истока - ребра ко всем буквам
    for (int i = 0; i < l_size; i++) {
        graph[0].push_back(i + 1);
        graph[i+1].push_back(0);
        flow[0].push_back(0);
        flow[i+1].push_back(0);
    }


    //от каждого кубика - ребро к стоку
    for (int i = 0; i < c_size; i++) {
        graph[l_size+1 + i].push_back(l_size + c_size + 1);
        graph[l_size + c_size + 1].push_back(l_size+1 + i);
        flow[l_size+1 + i].push_back(0);
        flow[l_size + c_size + 1].push_back(0);
    }

    vector<int> answer(l_size);

    int maxflow = 0;
    vector<int> parents;
    while (bfs(graph, flow, 0, c_size + l_size +1, parents)) {
        maxflow++;
        int v = c_size + l_size +1;
        while (v != 0) {
            for (int i = 0; i < graph[parents[v]].size(); i++) {
                if (graph[parents[v]][i] == v) {
                    if (parents[v] > 0 && parents[v] < l_size+1 && flow[parents[v]][i] == 0) {
                        answer[parents[v]-1] = v - l_size;
                    }
                    if (parents[v] > l_size && parents[v] < l_size+c_size && v > 0 && v < l_size+1 && flow[parents[v]][i] == -1) {
                        answer[v-1] = 0;
                    }
                    flow[parents[v]][i]++;
                    break;
                }
            }
            for (int i = 0; i < graph[v].size(); i++) {
                if (graph[v][i] == parents[v]) {
                    flow[v][i]--;
                    break;
                }
            }
            v = parents[v];

        }

    }


    if (maxflow == l_size) {
        cout << "Yes\n";
        for (int i=0; i< l_size; i++)
            cout << answer[i] <<' ';
    } else {
        cout << "No";
    }
    return 0;
}
